﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Luna.Extender;

namespace Luna.Framework.Extender
{
	class XmlServiceExtensionItem : XmlExtensionItem, IServiceExtensionItem, IServicePlaceHolder, IFormExtension
	{
		public XmlServiceExtensionItem(XmlExtensionManager manager, XmlNode node) : base(manager, node) { }

		public bool Startup {
			get { return this["startup"].convertTo<bool>(); }
		}

		public override object createExtension(IAppContext context) {
			return this;
		}

		#region IServicePlaceHolder Members

		bool IServicePlaceHolder.supportContract(Type contract) {
			return this.Type != null && contract.IsAssignableFrom(this.Type);
		}

		object IServicePlaceHolder.createInstance(IAppContext context) {
			return context.addService(base.createExtension(context));
		}

		#endregion

		#region IFormExtension Members

		void IFormExtension.extent(IAppContext context, System.Windows.Forms.Form form, IExtensionItem ep) {
			IAppContext c = form.getPropertyValue<IAppContext>("Context", null).getDefaultValue(context);
			c.addService(base.createExtension(c));
		}

		#endregion

		#region IServiceExtensionItem Members

		IServicePlaceHolder IServiceExtensionItem.createServicePlaceHolder() {
			return this;
		}

		#endregion
	}
}
